//
//  OrderInformationView.m
//  phmall
//
//  Created by admin on 2017/12/15.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "OrderInformationView.h"

@implementation OrderInformationView

-(instancetype)init{
    if (self=[super init]) {
        self.priceView=[[UIView alloc]init];
        self.priceView.backgroundColor=[UIColor whiteColor];
        [self addSubview:self.priceView];
        
        self.priceLabel=[[UILabel alloc]init];
        self.priceLabel.text=@"商品总价:";
        [self.priceView addSubview:self.priceLabel];
        self.priceLabel.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.priceLabel.font=[UIFont systemFontOfSize:13];
        
        self.price=[[UILabel alloc]init];
        self.price.text=@"₱8888.80";
        [self.priceView addSubview:self.price];
        self.price.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.price.font=[UIFont systemFontOfSize:13];
        
        self.freightLabel=[[UILabel alloc]init];
        self.freightLabel.text=@"运费:";
        [self.priceView addSubview:self.freightLabel];
        self.freightLabel.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.freightLabel.font=[UIFont systemFontOfSize:13];
        
        self.freight=[[UILabel alloc]init];
        self.freight.text=@"₱8888.80";
        [self.priceView addSubview:self.freight];
        self.freight.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.freight.font=[UIFont systemFontOfSize:13];
        
        self.discountsLabel=[[UILabel alloc]init];
        self.discountsLabel.text=@"优惠:";
        [self.priceView addSubview:self.discountsLabel];
        self.discountsLabel.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.discountsLabel.font=[UIFont systemFontOfSize:13];
        
        self.discounts=[[UILabel alloc]init];
        self.discounts.text=@"₱8888.80";
        [self.priceView addSubview:self.discounts];
        self.discounts.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.discounts.font=[UIFont systemFontOfSize:13];
        
        self.totalLabel=[[UILabel alloc]init];
        self.totalLabel.text=@"订单总价:";
        [self.priceView addSubview:self.totalLabel];
        self.totalLabel.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.totalLabel.font=[UIFont systemFontOfSize:13];
        
        self.total=[[UILabel alloc]init];
        self.total.text=@"₱8888.80";
        [self.priceView addSubview:self.total];
        self.total.textColor=[UIColor orangeColor];
        self.total.font=[UIFont systemFontOfSize:13];
        
        self.codeView=[[UIView alloc]init];
        self.codeView.backgroundColor=[UIColor whiteColor];
        [self addSubview:self.codeView];
        
        self.number=[[UILabel alloc]init];
        self.number.text=@"订单编号:OD150991254852";
        [self.codeView addSubview:self.number];
        self.number.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.number.font=[UIFont systemFontOfSize:13];
        
        self.time=[[UILabel alloc]init];
        self.time.text=@"2017-10-11 20:23:22";
        [self.codeView addSubview:self.time];
        self.time.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.time.font=[UIFont systemFontOfSize:13];
    }
    return self;
}
-(void)layoutSubviews{
    [super layoutSubviews];
    CGSize superSize = self.frame.size;
    
    if (CGSizeEqualToSize(superSize, CGSizeZero)) {
        return;
    }
    [self.priceView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.offset(0).priorityHigh();
        make.bottom.equalTo(self.totalLabel.mas_bottom).offset(10).priorityHigh();
    }];
    
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(8);
        make.left.offset(10);
    }];
    
    [self.price mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.priceLabel).offset(0);
        make.right.offset(-10);
    }];
    
    [self.freightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.priceLabel.mas_bottom).offset(8);
        make.left.offset(10);
    }];

    [self.freight mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.freightLabel).offset(0);
        make.right.offset(-10);
    }];

    [self.discountsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.freightLabel.mas_bottom).offset(8);
        make.left.offset(10);
    }];

    [self.discounts mas_makeConstraints:^(MASConstraintMaker *make) {
       make.centerY.equalTo(self.discountsLabel).offset(0);
        make.right.offset(-10);
    }];

    [self.totalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.discountsLabel.mas_bottom).offset(8);
        make.left.offset(10);
     
    }];

    [self.total mas_makeConstraints:^(MASConstraintMaker *make) {
         make.centerY.equalTo(self.totalLabel).offset(0);
        make.right.offset(-10);
    }];
    
    [self.codeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0).priorityHigh();
        make.top.equalTo(self.priceView.mas_bottom).offset(10);
//        make.bottom.equalTo(self.totalLabel.mas_bottom).offset(10).priorityHigh();
    }];
    
    [self.number mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(8);
        make.left.offset(10);
    }];
    
    [self.time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.number.mas_bottom).offset(8);
        make.left.offset(10);
        make.bottom.offset(-8);
    }];
}
-(void)setModel:(OrderModel *)model{
   
    self.price.text=model.goods_amount;
    self.freight.text=model.sh_price;
    self.discounts.text=model.discount;
    self.total.text=[NSString stringWithFormat:@"%.0f",model.goods_amount.doubleValue+model.sh_price.doubleValue+model.discount.doubleValue];
    self.time.text=[NSString stringWithFormat:@"下单时间:%@",[PublicClass timeWithTimeIntervalString:model.addtime]];
}
@end
